﻿using Newtonsoft.Json;
using System;

namespace CMS.Infos
{
    public class Building : ICloneable, IAssignable
    {
        [JsonProperty(PropertyName = "name")]
        public string Name { get; set; }

        [JsonProperty(PropertyName = "key", NullValueHandling = NullValueHandling.Ignore)]
        public string Key { get; set; }

        public object Assign(object src)
        {
            if (src is Building src2)
            {
                Name = src2.Name;
                Key = src2.Key;
            }
            else
            {
                throw new ArgumentException();
            }
            return this;
        }

        public object Clone()
        {
            return new Building() { Name = Name, Key = Key };
        }

        public override bool Equals(object obj)
        {
            if (obj is Building building)
            {
                return Name == building.Name && Key == building.Key;
            }
            else
            {
                return false;
            }
        }

        public override int GetHashCode()
        {
            return (Name?.GetHashCode() ?? 0) ^ (Key?.GetHashCode() ?? 0);
        }

        public override string ToString()
        {
            return Name;
        }

    }
}
